﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Collections;
using Winter.BackEnd.Models.DataTypes;

namespace Winter.BackEnd.Models.Domain
{
    public partial class Student : IPerson
    {
        public string Role
        {
            get
            {
                return UserRoles.Student.RoleName;
            }
        }

        public string FullName
        {
            get
            {
                return Person.FirstName + " " + Person.SecondName + " " + Person.LastName;
            }
        }

        public string Sex
        {
            get
            {
                return Person.Sex.Caption;
            }
        }

        public string BirthDate
        {
            get
            {
                return Person.Birthdate.Value.ToShortDateString();
            }
        }

        public string Email
        {
            get { return Person.Email; }
        }

        public string FacultyName
        {
            get
            {
                return Group.Department.Faculty.Name;
            }
        }

        public string DepartmentName
        {
            get
            {
                return Group.Department.Name;
            }
        }

        public string GroupName
        {
            get
            {
                return Group.Name;
            }
        }

        public ICollection Duties
        {
            get
            {
                Hashtable duties = new Hashtable();
                duties.Add("facultyName", FacultyName);
                duties.Add("departmentName", DepartmentName);
                duties.Add("groupName", GroupName);
                return duties;
            }
        }

        public IList<Winter.BackEnd.Models.DataTypes.Message> RecievedMessages
        {
            get
            {
                List<Winter.BackEnd.Models.DataTypes.Message> messages = new List<Winter.BackEnd.Models.DataTypes.Message>();
                foreach (var message in Person.PersonMessages)
                {
                    messages.Add(new Winter.BackEnd.Models.DataTypes.Message()
                    {
                        MessageBody = message.Message.Body,
                        Sender = Repository.CurrentDataContext.Persons.FirstOrDefault(p => p.ID == message.Message.SenderID).FullName,
                        Time = message.Message.SendTime.ToString()
                    });
                }
                return messages;
            }
        }

        public IEnumerable<MenuLink> NavigationMenu
        {
            get
            {
                List<MenuLink> menu = new List<MenuLink>();
                menu.Add(new MenuLink()
                {
                    LinkText = "Profile",
                    ActionName = "Index",
                    ControllerName = "Person"
                });
                menu.Add(new MenuLink()
                {
                    LinkText = "Group",
                    ActionName = "Index",
                    ControllerName = "Group"
                });
                menu.Add(new MenuLink()
                {
                    LinkText = "Subjects",
                    ActionName = "Index",
                    ControllerName = "Classes"
                });
                menu.Add(new MenuLink()
                {
                    LinkText = "Messages",
                    ActionName = "Index",
                    ControllerName = "Message"
                });
                return menu;
            }
        }

        public static bool IsStudent(Person person)
        {
            return person.Students.Count() != 0;
        }
    }
}
